package com.cloud.ck.controller;

import com.cloud.ck.entity.SysLog;
import com.cloud.ck.service.ChickHouserService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@RestController
public class ClickController {

    @Resource
    private ChickHouserService chickHouserService;

    @GetMapping(value = "/clickHouseQuery")
    public List<SysLog> query() {
        return chickHouserService.query();
    }

    @GetMapping(value = "/ckInsert")
    public void insert() {
        SysLog sysLog = new SysLog();
        sysLog.setUserId(1);
        sysLog.setVersion("11");
        sysLog.setRegTime(new Date());
        sysLog.setAppId("123");
        chickHouserService.insertLog(sysLog);
    }

    @GetMapping(value = "/ckCreatTable")
    public void creatTable() {
        chickHouserService.creatTable("sys_log");
    }

    @GetMapping(value = "ckBatchInsert")
    public void batchInsert() {

        List<SysLog> listRecord = new ArrayList();
        for (int i = 0; i < 1000; i++) {
            SysLog record = new SysLog();
            record.setUserId(i);
            record.setVersion(String.valueOf(i + 1));
            record.setAppId("123");
            record.setRegTime(new Date());
            listRecord.add(record);
        }
        chickHouserService.batchInsert(listRecord);
    }

}
